package com.qch.rocketmq.springboot_ms_rocketmq.rocketmq.producer;

import com.alibaba.fastjson.JSONObject;
import com.qch.rocketmq.springboot_ms_rocketmq.pojo.OrderDO;
import com.qch.rocketmq.springboot_ms_rocketmq.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author qch
 * @Date 2021/6/7
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "tp_goods_order",consumerGroup = "consumer_grp_order")
public class MyRocketListener implements RocketMQListener<String> {

    @Autowired
    private GoodsService goodsService;
    @Override
    public void onMessage(String message) {
        log.info("生成订单ing...: {}", message);
        try {
            OrderDO orders = JSONObject.parseObject(message, OrderDO.class);
            goodsService.proOrder(orders);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
